package api

import (
	"ginfast/app/system/dto"
	"ginfast/app/system/model"
	"ginfast/app/system/service"
	"ginfast/pkg/ginx"
	"ginfast/util"
)

// LoginLog
type LoginLog struct {
}

// ListHandler 列表
func (LoginLog) ListHandler(c *ginx.Context) {
	var p dto.Where
	if err := c.MustBind(&p); err != nil {
		return
	}
	var data []model.LoginLog
	total, _ := p.DbModelWhere(&model.LoginLog{}).Find(&data)
	c.JSONWriteTotal(total, data)
}

// DeleteHandler 删除
func (LoginLog) DeleteHandler(c *ginx.Context) {
	util.Deletes(&model.LoginLog{}, c)
}

// ClearHandler 清空
func (LoginLog) ClearHandler(c *ginx.Context) {
	service.Clear(&model.LoginLog{}, c)
}

func (o LoginLog) Routers(r *ginx.RouterGroup) {
	r.GET("/list", o.ListHandler)
	r.DELETE("/:id", o.DeleteHandler)
	r.DELETE("/clear", o.ClearHandler)
}
